"""
@Project:ruiji
@File:myjwt.py
@Author:马可
@Date:下午 02:13
"""

import jwt
import time
from sqlalchemy import true,false

class MyJwt:
    def __init__(self) -> None:
        self.secret="weiuavilfeliugot86R574687%^&"

        # 加密
        def jwt_encode(self,data):
            return jwt.encode(data,self.secret,algorithm="HS256")

        # 解密
        def jwt_decode(self,token):
            payload = jwt.decode(token,self.secret,algorithms="HS256")
            return payload

        # 对比
        def check(self,token):
            payload = jwt.decode(token,self.secret,algorithms="HS236")
            newtoken = jwt.encode(payload,self.secret,algorithm="HS256")

            if token == newtoken:
                # 验证过期时间
                nowtime = int(time.time())
                if nowtime - payload['data']['exp']>3600:
                    return false
                return true
            return false


myjwt = MyJwt()